<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\controller\HomeBaseController;

class SearchController extends HomeBaseController
{
    /**
     * 搜索
     * @return mixed
     */
    public function index()
    {
        $keyword = $this->request->param();

        // if (empty($keyword)) {
        //     $this -> error("关键词不能为空！请重新输入！");
        // }


        //搜索新闻
        //$list_news=db('news')->where($map)->where('status',1)->select();
        //搜索代理记帐
        //$list_dljz=db('product')->where($map)->where('status',1)->select();
        //数组合并
        // $list = array_merge($list_news,$list_dljz);

        //模糊查询
        $map['post_title']=['like',"%". $keyword['keyword']."%"];
        //搜索新闻
        $list=db('product_post')->where($map)->where('post_status',1)->where('delete_time','0')->order('published_time desc')->paginate(12)->each(function($img){

            $img['more']=json_decode($img['more'],true);
            return $img;
        });
        $params=$this->request->param();
        $list->appends($params);
        $this ->assign('list',$list);
        $this->assign('page1', $list->render());//单独提取分页出来
       // halt($list->render());




        // $this -> assign("keyword", $keyword);
        return $this->fetch('/search');
    }
}
